from flask import Flask,jsonify,request,Blueprint,session
from common.res import (getRes,getErrorRes,getSuccessRes,getDataRes)
from common.sqlInjectionSecurity import sqlEscape,sqlEscapeField
from DAL.admDAL import logDAL

adm_log = Blueprint('adm_log',__name__)

@adm_log.route("/adm_log/getlist",methods=['POST'])
def getlist():
    param = {
        'start': request.form.get('start') and sqlEscape(request.form.get('start')) or None,
        'end': request.form.get('end') and sqlEscape(request.form.get('end')) or None,
        'name': request.form.get('name') and sqlEscape(request.form.get('name')) or "",
        'content': request.form.get('content') and sqlEscape(request.form.get('content')) or None,
        'sql_record': request.form.get('sql_record') and sqlEscape(request.form.get('sql_record')) or None,
        'page': request.form.get('page') and sqlEscape(request.form.get('page')) or 1,
        'limit': request.form.get('limit') and sqlEscape(request.form.get('limit')) or 20,
        'filed': request.form.get('filed') and sqlEscape(request.form.get('filed')) or 'id',
        'sort': request.form.get('sort') and sqlEscape(request.form.get('sort')) or 'ascending'
          }
    dal = logDAL()
    data,count = dal.getList(**param)
    if data:
        res = getSuccessRes(data=data,count=count)
    else:
        res = getSuccessRes(data=[], count=count)
    return jsonify(res)


